// WechatPushController.java
package com.baoyouqun.controller;

import com.alibaba.cola.dto.Response;
import com.alibaba.cola.dto.SingleResponse;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baoyouqun.domain.Query.WechatPushQuery;
import com.baoyouqun.domain.VO.SmsTemplateDTO;
import com.baoyouqun.domain.VO.WechatPushDTO;
import com.baoyouqun.domain.VO.WechatPushVO;
import com.baoyouqun.service.SystemConfigService;
import com.baoyouqun.service.WechatPushService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.validation.Valid;
import org.springframework.web.bind.annotation.*;

import java.io.IOException;

@RestController
@RequestMapping("/api/wechat/push")
@Api(tags = "微信服务号推送管理")
public class WechatPushController {

    @Resource
    private WechatPushService wechatPushService;
    @Resource
    private SystemConfigService systemConfigService;

    @PostMapping
    @ApiOperation("新增推送")
    public Response create(@Valid @RequestBody WechatPushDTO dto) {
        // 实际应用中需从登录信息获取操作人ID
        wechatPushService.createPush(dto, "当前登录用户ID");
        return Response.buildSuccess();
    }

    @GetMapping("/page")
    @ApiOperation("分页查询推送记录")
    public SingleResponse<IPage<WechatPushVO>> page(WechatPushQuery query) {
        return SingleResponse.of(wechatPushService.pagePush(query));
    }

    @GetMapping("/export")
    @ApiOperation("导出推送记录")
    public void export(WechatPushQuery query, HttpServletResponse response) throws IOException {
        wechatPushService.exportPush(query, response);
    }


    /**
     * （可选）查询当前阿里云短信模板配置（ID+内容）
     */
    @ApiOperation("查询阿里云短信模板配置（ID+内容）")
    @GetMapping("/sms-template")
    public SmsTemplateDTO getSmsTemplate() {
        return systemConfigService.getSmsTemplate();
    }
}